package com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.PreservationContract;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.PreservationPresenter;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/22 17:38
 * 功能描述： 提现界面
 * 联系方式：1037438704@qq.com
 */
public class PreservationActivity extends BaseActivity implements PreservationContract {
    @BindView(R.id.image_left_finish)
    ImageView imageleftFinish;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.text_right)
    TextView textRight;
    @BindView(R.id.text_presentation)
    TextView textPresentation;
    @BindView(R.id.text_shouxufei)
    TextView text_shouxufei;
    @BindView(R.id.text_zhifubao)
    TextView text_zhifubao;
    @BindView(R.id.edit_tixian)
    EditText edit_tixian;
    private PreservationPresenter preservatio;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_preservation;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        String zhifubao = getIntent().getExtras().getString("zhifubao");
        text_zhifubao.setText("支付宝" + zhifubao);
        preservatio = new PreservationPresenter(this, this);
        textCenter.setText("提现");
        imageleftFinish.setVisibility(View.VISIBLE);
        edit_tixian.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s != null) {
                    String service_charge = s.toString();
                    preservatio.serviceCharge(service_charge);
                }
            }
        });
    }

    @OnClick({R.id.image_left_finish, R.id.text_presentation})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left_finish:
                finish();
                break;
            case R.id.text_presentation:
//                是否vip 1否 2是           1未认证 2 已认证
                if (getSex.equals("1")) {
                    if (getVip.equals("1")) {
                        ToastUtil.show("成为Vip后才能提现");
                        return;
                    } else {
                        preservatio.addWithdraw(token, edit_tixian.getText().toString().trim(), service);
                    }
                } else {
                    if (getIdentification.equals("1")) {
                        ToastUtil.show("认证后才能提现");
                        return;
                    } else {
                        preservatio.addWithdraw(token, edit_tixian.getText().toString().trim(), service);
                    }
                }

                break;
            default:
        }
    }

    String service;

    @Override
    public void Success(Map<String, String> data) {
        service = data.get("service");
        text_shouxufei.setText(service);
    }

    @Override
    public void Failed(String msg) {

    }

    @Override
    public void showLoading() {

    }
}
